<?php
class Shop_model extends CI_Model {
    
   
    private $_tabla = 'shop';
    private $_tabla_2 = 'shop_details';
    
  /*  public function addPurchase($data)
    {
        return $this->db->insert($this->_tabla, $data);
    }*/

    public function add_shop($data){
       return $this->db->insert($this->_tabla, $data);
    }
    
    public function add_shop_dateils($data){
       return $this->db->insert($this->_tabla_2, $data);
    }
    
    public function search_shop_deatils($document_code){
       
        $query = $this->db->query("SELECT p.code,p.description, sd.box, sd.pack, sd.unit, p.price, sd.amount FROM products as p, shop_details as sd where p.code = sd.product_code and sd.document_code = '".$document_code."'");
        $rs = $query->result();
        return $rs;                      
    }
    
    public function delete_detail($document_code, $code){
       return $this->db->query("DELETE FROM shop_details WHERE  document_code='".$document_code."' AND product_code ='".$code."'");
    }
    
    public function delete_detail_2($document_code, $code){
       return $this->db->query("DELETE FROM shop_details WHERE  document_code='".$document_code."'");
    }
    
    public function update_shop($document_code,$data)
    {        
        $this->db->where('document_code', $document_code);
        $this->db->update('shop', $data); 
    }
    
    public function search_shop($document_code){

        
        $this->db->select();
        $this->db->where('document_code', ''.$document_code.'');
        $query = $this->db->get($this->_tabla);
        $rs = $query->result();
        
        return $rs;
        
    }
    
    public function edit_amout($document_code,$amount){
         return $this->db->query("UPDATE shop SET amount='".$amount."' WHERE `document_code`='".$document_code."'");
    }
    
    public function comparaction_code($document_code){
        $query = $this->db->query("SELECT document_code FROM shop where document_code = '".$document_code."'");
        $rs = $query->num_rows();
        return $rs;
    }
    
     public function select_almacen_productos($code_product, $code_almacen){
       $query = $this->db->query("SELECT * FROM `warehouses_product` WHERE `id_product` = '".$code_product."' and `id_warehouse` = '".$code_almacen."'");
       $rs = $query->result();
       return $rs;
    }
    
    
    
    
    
}